package models;


import helpers.Paillier;

import java.math.BigInteger;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import play.data.validation.MaxSize;
import play.data.validation.Required;
import play.db.jpa.Model;

@Entity
public class Answer extends Model {
	@ManyToOne
	public User voter;

	@ManyToOne
	public Question question;

	
	//Encrypted candidate name for the answer
	@Column(columnDefinition = "text")
	public BigInteger candidateName;

	@Embedded
	Paillier p= new Paillier();

	
	public Answer(Candidate candidate) {
		 
		// this.candidate=candidate;
		question = candidate.question;
		candidateName = p.stringEncryption(candidate.CandidateName);
		candidate.Count++;
		candidate.save();
		this.save();

	}

	
	public String getCandidateName() {

		return p.stringDecryption(candidateName);
	}

}